package com.ming.seatMonitoring.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ming.seatMonitoring.pojo.DO.BookRoomInfoDO;
import com.ming.seatMonitoring.pojo.entity.ResultBody;
import com.ming.seatMonitoring.service.UseManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

/**
 * @author 小明
 * @date 2021/10/23
 * @description
 */
@RestController
@RequestMapping("/useManage")
public class UseManageController {
    @Autowired
    UseManageService useManageService;

    /**
     * 按房间号查询近七天借用次数。
     * @param roomId
     * @return
     */
    @RequestMapping("/getWeek")
    public ResultBody getWeek(@RequestParam(value = "roomId") int roomId){
        final int[] week = useManageService.getWeek(roomId);
        int all = 0;
        for (int i = 0; i < week.length; i++) {
            all = all + week[i];
        }
        return ResultBody.ok().data("week",week).data("weekAll",all);
    }

    /**
     * 统计某用户总借用次数+具体情况
     * @param userId
     * @param pageNumber
     * @param size
     * @return
     */
    @RequestMapping("getTotalByUser")
    public ResultBody getCountByUserId(@RequestParam String userId,
                                       @RequestParam(defaultValue = "1") @NotEmpty String pageNumber,
                                       @RequestParam(defaultValue = "10") @NotEmpty String size){
        Long PageNumber = Long.valueOf(pageNumber);
        Long Size = Long.valueOf(size);
        Page<BookRoomInfoDO> page = new Page<>(PageNumber,Size);
        final Page<BookRoomInfoDO> date = useManageService.getCountByUserId(page, userId);
        final int total = useManageService.getTotal(userId);
        return ResultBody.ok().data("total",total).data("data",date);
    }

    /**
     * 统计某房间总借用次数+具体情况
     * @param roomId
     * @param pageNumber
     * @param size
     * @return
     */
    @RequestMapping("/getTotalByRoom")
    public ResultBody getCountByRoomId(@RequestParam int roomId,
                                       @RequestParam(defaultValue = "1") @NotEmpty String pageNumber,
                                       @RequestParam(defaultValue = "10") @NotEmpty String size){
        Long PageNumber = Long.valueOf(pageNumber);
        Long Size = Long.valueOf(size);
        Page<BookRoomInfoDO> page = new Page<>(PageNumber,Size);
        final Page<BookRoomInfoDO> date = useManageService.getListByRoomId(page, roomId);
        final int total = useManageService.getCountByRoomId(roomId);
        return ResultBody.ok().data("total",total).data("data",date);
    }

}
